package com.cy.java.net;

import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class MainServer {//服务端
    public static void main(String[] args) throws IOException {
        //tomcat
        //创建ServerSocket对象,并在999端口进行监听浏览器的监听
        ServerSocket serverSocket=new ServerSocket(999);
        System.out.println("server start on 9999 port");
        //等待客户端的链接
        //不断接收客户端的请求
        while (true){
            Socket socket=serverSocket.accept();
            //客户端连接到服务端以后会据需向下执行
            System.out.println("client 来了");
            //通过流读取客户端服务端发送请求数据
            String threadName=Thread.currentThread().getName();
            System.out.println("threadName="+threadName);
            ObjectInputStream in = new ObjectInputStream(socket.getInputStream());
            String content=in.readUTF();
            System.out.println("client  say" +content);

        }

        }

}
